package com.fenqing.comics.service.impl;

import com.fenqing.comics.service.IAsyncService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.function.Supplier;

/**
 * 异步服务实现类
 * @author fenqing
 */
@Service
public class AsyncServiceImpl implements IAsyncService {

    @Override
    @Async
    public <T> Future<T> asyncMethod(Supplier<T> supplier) {
        T result = supplier.get();
        return CompletableFuture.completedFuture(result);
    }

    @Override
    @Async
    public Future<Void> asyncMethod(Runnable runnable) {
        runnable.run();
        return CompletableFuture.completedFuture(null);
    }

}
